package com.bafa.front.events;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.bafa.dbcache.LeagueCache;
import com.bafa.email.Email;
import com.bafa.jdbc.DBAccess;
import com.bafa.objects.PageBean;
import com.bafa.objects.team.Team;
import com.bafa.services.RetrieveServices;
import com.bafa.services.UserServices;

public class ResetPasswordEvent extends Event {

	@Override
	public void doEvent(HttpServletRequest request,
			HttpServletResponse response, PageBean page) {
		UserServices.resetPassword(new Integer(request.getParameter("teamId")));
		message.addMessage("Password successfully reset");
		page.addDetails(RetrieveServices.getPage("admin"));
		Team team = RetrieveServices.getTeam(request.getParameter("teamId"));
		String[] emails = { team.getPrimaryContactEmail(),
				team.getSecondaryContactEmail() };
		StringBuffer body = new StringBuffer();
		String subject = "";

		subject = "Confirmation of password reset";
		body.append("Your password has been reset to ");
		body.append("If you have any queries please contact ");
		body.append(new DBAccess().retrieveReference("adminemailaddress"));

		Email.sendEmail(new DBAccess().retrieveReference("adminemailaddress"),
				emails, subject, body.toString());
	}

}
